package com.ershi.spring.aop.annotation.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author 二十
 * @since 2021/10/18 12:05 上午
 */
@Component("logging")
@Aspect
public class Logging {
	@Before(value="execution(* com.ershi.spring.aop.annotation.service.AddImpl.*(..))")
	public void before(JoinPoint jp){
		Object[] args = jp.getArgs();
		String name = jp.getSignature().getName();
		System.out.println("before..."+name+"..."+Arrays.toString(args));
	}
	@AfterReturning(value="execution(* com.ershi.spring.aop.annotation.service.AddImpl.*(..))",returning = "result")
	public void afterReturning(JoinPoint jp,Object result){
		Object[] args = jp.getArgs();
		String name = jp.getSignature().getName();
		System.out.println("afterReturning..."+name+"..."+ Arrays.toString(args)+"..."+result);
	}
	@AfterThrowing(value="execution(* com.ershi.spring.aop.annotation.service.AddImpl.*(..))",throwing = "e")
	public void afterThrowing(JoinPoint jp, Exception e){
		Object[] args = jp.getArgs();
		String name = jp.getSignature().getName();
		System.out.println("afterThrowing..."+name+"..."+Arrays.toString(args)+"..."+e);
	}
	@After("execution(* com.ershi.spring.aop.annotation.service.AddImpl.*(..))")
	public void after(JoinPoint jp){
		Object[] args = jp.getArgs();
		String name = jp.getSignature().getName();
		System.out.println("after..."+name+"..."+Arrays.toString(args));
	}
}